import { ref, reactive } from "vue";
import { selectMerchantGames, selectGames, merchantSignSelect } from "@/api";
import { message } from "@/utils/message";
import { formatOptions } from "@/utils";
export function useTable() {
  /**
   * 分页
   */
  const pagination = reactive({
    align: "right",
    currentPage: 1,
    pageSize: 10,
    background: true,
    total: 0
  });
  /**
   * 表头样式
   */
  const headerCellStyle = {
    background: "var(--el-fill-color-light)",
    color: "var(--el-text-color-primary)"
  };
  /**
   * 获取号商账号类型游戏下拉列表
   */
  const gameMerchantOptions = ref([]);
  async function getSelectMerchantGames() {
    const res = await selectMerchantGames();
    if (!res?.success) {
      message(res.info, { type: "error" });
      return;
    }
    gameMerchantOptions.value = formatOptions(res.data, {
      value: "gameCode",
      label: "gameName"
    });
  }
  /**
   * 获取盼之开头的账号类型游戏列表
   */
  const gameV2Options = ref([]);
  async function getSelectV2Games() {
    const res = await selectGames();
    if (!res?.success) {
      message(res.info, { type: "error" });
      return;
    }
    gameV2Options.value = formatOptions(res.data, {
      value: "gameCode",
      label: "gameName"
    });
  }
  /**
   * 获取渠道下拉列表
   */
  const channelOptions = ref([]);
  async function getChannelSelect() {
    const res = await merchantSignSelect();
    if (!res.success) {
      message(res.info, { type: "error" });
      return;
    }
    channelOptions.value = formatOptions(res.data, {
      value: "channelId",
      label: "remark"
    });
  }

  /**
   * 返回结果
   */
  return {
    pagination,
    headerCellStyle,
    getSelectMerchantGames,
    gameMerchantOptions,
    getSelectV2Games,
    gameV2Options,
    getChannelSelect,
    channelOptions
  };
}
